package list

func removeElements(head *ListNode, val int) *ListNode {

	if head == nil {
		return nil
	}

	head.Next = removeElements(head.Next, val)

	if head.Val == val {
		return head.Next
	}
	return head

}

func removeElements2(head *ListNode, val int) *ListNode {

	dummyHead := &ListNode{Next: head}

	for temp := dummyHead; temp.Next != nil; {
		if temp.Next.Val == val {
			temp.Next = temp.Next.Next
		} else {
			temp = temp.Next
		}
	}

	return dummyHead.Next
}
